// 图片轮播表单提交
$('.slidesForm').on('submit', function() {
  let formdata = $(this).serialize()
  $.ajax({
    type: 'post',
    url: '/slides',
    data: formdata,
    success: function(response) {
      location.reload()
    },
    error: function() {
      alert('添加失败')
    }
  })
})
//文件上传
$('.fileInput').on('change', function() {
  let formData = new FormData()
  formData.append('avatar', this.files[0])
  $.ajax({
    type: 'post',
    url: '/upload',
    data: formData,
    processData: false,
    contentType: false,
    success: function(response) {
      $('#slidesHideen').val(response[0].avatar)
    }
  })
})
$.ajax({
  type: 'get',
  url: '/slides',
  success: function(response) {
    let html = template('slideFormTpl', {data: response})
    $('.slideTable tbody').html(html)
  }
})
$('.slideTable').on('click', '.deleteSlide', function() {
 if(confirm('你确定进行删除操作吗')) {
  let id = $(this).attr('data-id')
  $.ajax({
    type: 'delete',
    url: '/slides/'+id,
    success: function() {
      location.reload()
    }
  })
 }
})